<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial - scale=1.0">
    <link rel="stylesheet" href="../static/css/behindManager.css" th:href="@{/css/behindManager.css}">
    <link rel="stylesheet" href="../static/css/iconfont.css" th:href="@{/css/iconfont.css}">
    <link rel="stylesheet" href="../static/css/confirm.css" th:href="@{/css/confirm.css}">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <title>举报管理</title>
</head>
<body>
<div class="box">
    <div class="nav-container">
        <div class="logo">
            <img src="../static/img/logo.png" alt="Ant Design Pro" th:src="@{/img/logo.png}">
            <p class="name">Haven Manager</p>
        </div>
        <div class="user-info">
            <span class="username">后台管理</span>
        </div>
        <ul class="nav">
            <li><a href="http://localhost:8080/admin/behindManagerUser" th:href="@{/admin/behindManagerUser}"  data-target="adminManagement" class="nav-link ">用户管理</a></li>
            <li><a href="http://localhost:8080/admin/behindManagerPost" th:href="@{/admin/behindManagerPost}" data-target="systemManagement" class="nav-link">帖子管理</a></li>
            <li><a href="http://localhost:8080/admin/behindManagerCategory" th:href="@{/admin/behindManagerCategory}" data-target="kindManagement" class="nav-link ">类别管理</a></li>
            <li><a href="http://localhost:8080/admin/behindManagerReport" th:href="@{/admin/behindManagerReport}" data-target="jubaoManager" class="nav-link active">举报管理</a></li>
        </ul>
    </div>
    <a href="http://localhost:8080/mainPageRecommend" th:href="@{/mainPageRecommend}" style="position: static"><button class="back" style="z-index: 100">返回首页</button></a>
    <a href="" class="person"><img src="../static/img/image1.png " alt=""  th:src="${admin.avatar}">
        <div class="admin-name"  th:text="${admin.username}"></div></a>
    <div id="jubaoManager" class="content ">
        <button id="check-button">全部驳回</button>
        <button id="pass-button">全部通过</button>
        <input type="text" id="check" class="checked" placeholder="请输入被举报人昵称">
        <button id="checkkey-button" class="add-button">查询</button>
        <div><i class="iconfont" id="backform" >&#xe61b;</i></div>
        <table class="adminManagement-table">
            <thead>
            <tr>
                <th><input type="checkbox" class="selectAll"></th>
                <th>举报人</th>
                <th>被举报人</th>
                <th>举报原因</th>
                <th>举报内容</th>
                <th>详情</th>
                <th>操作</th>
            </tr>
            </thead>
            <div>
                <p id="notice" style="position: absolute;top: 300px;left: 400px;font-size: 22px;font-weight: 700; display: none">没有找到该举报</p>
            </div>
            <tbody id="table-body">
            <tr th:each="report, stat : ${reportInfoList}" >
                <td><input type="checkbox" class="rowCheckbox" th:value="${report.id}" th:data-id="${report.id}"></td>
                <!-- 举报人 -->
                <!-- 被举报人 -->
                <td th:text="${postUserList[stat.index]}"></td>
                <td th:text="${reporterList[stat.index]}"></td>
                <td th:text="${report.reportReason}"></td>
                <td class="title-cell">
                    <div class="contents" th:text="${postList[stat.index].content}"></div>
                </td>
                <td>
                    <button class="reportedit" th:data-id="${report.id}"  th:attr="data-index=${stat.index}" >详情</button>
                </td>
                <td>
                    <button class="deletebtn" th:data-id="${report.id}">驳回</button>
                    <button class="editbtns text-xl" th:data-id="${report.id}">通过</button>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="pagination" id="pageNav"></div></div>
    <!-- 举报详情 -->
    <div id="reportEditModal" class="modal" style="display: none;">
        <div class="bg">
            <div class="title-edit">详情栏</div>
            <ul id="detailContent">
             </ul>
            <button class="cancelEditPost" style="margin-left: 576px ;margin-top:59px;">返回</button>
        </div>
    </div>
        </div>
    <script th:inline="javascript">
        const reportInfoList = /*[[${reportInfoList}]]*/ [];
        const reporterList = /*[[${reporterList}]]*/ [];     // 补充分号，避免语法错误
        const postList = /*[[${postList}]]*/ [];                           // 举报内容列表
        // 2. 显示详情：根据按钮的索引渲染对应数据
        function showDetail(btn) {
            // 获取按钮上绑定的索引（与表格行索引一致）
            console.log(1231)
            const index = parseInt(btn.getAttribute('data-index'));
            console.log(index)
            if (isNaN(index)) {
                showCustom('数据索引错误', 3000);
                return;
            }
            document.getElementById('reportEditModal').style.display = 'block';
            // 根据索引获取对应行的数据（容错处理，避免索引越界）
            const report = reportInfoList[index] || {};         // 当前举报信息
            const postUser = reporterList [index] || '未知';      // 当前被举报人
            const post = postList[index] || {content: '无内容'}; // 当前举报内容
            console.log(reportInfoList)
            console.log(reporterList)
            console.log(post)
            console.log( postList)

            // 3. 动态生成详情 HTML 并插入弹窗
            const detailContainer = document.getElementById('detailContent');
            detailContainer.innerHTML = `
        <li>
            <label for="namePostTitle" class="lable1">被举报人为：
                <input type="text" id="namePostTitle" class="PostTitle"
                       placeholder="昵称" value="${postUser}"
                       style="margin-left: 15px;background-color: white;" disabled="disabled">
            </label>
        </li>
        <li>
            <label for="editPostTitle" class="lable1">举报原因为：
                <input type="text" id="editPostTitle" class="EditPostTitle"
                       placeholder="帖子标题" style="background-color: white;" value="${report.reportReason || '无'}" disabled="disabled">
            </label>
        </li>
        <li>
            <label class="lable1">举报内容为：</label>
        </li>
        <div id="editPostContentDivs"
             class="border border-gray-300 p-2 rounded-md w-full h-32 mb-2"
             style="overflow-y: auto; white-space: pre-line; margin-top: -21px;margin-left: 130px;"
             contenteditable="true" disabled="disabled" onfocus="this.blur();">
            ${post.content}
        </div>
    `;

        }

    </script>
    <script src="../static/js/behindMangerReport.js" th:src="@{/js/behindMangerReport.js}"></script>
</body>

</html>